<template>
  <div class="top" style="display: flex; align-items: center">
    <p class="left" style="
        width: 8px;
        height: 25px;
        background-color: #f6d39c;
        margin-right: 10px;
        border-radius: 3px;
      "></p>
    <p style="color: white; font-size: 22px; font-weight: 600">{{ $t('留言反馈') }} </p>
  </div>

  <div class="box1" style="display: flex; margin-top: 30px">
    <div class="leftbottom" style="
        display: flex;
        justify-content: flex-end;
        margin-bottom: 20px;
        align-items: center;
      ">
      <div style="
          height: 27px;
          border-radius: 5px;
          background-color: #f6d39c;
          margin-right: 10px;
          display: inline-block;
           padding-left: 5px;
            padding-right: 5px;
            padding-top: 2px;
            box-sizing: border-box;
        " @click="open">
        <el-icon style="font-size: 14px; margin-right: 5px">
          <Edit />
        </el-icon>
        <span style="font-size: 13px">{{ $t('留言') }} </span>
      </div>
    </div>
  </div>
  <div class="box2">
    <div class="inner inner2">
      <span>{{ $t('类型') }} :</span>
      <el-select v-model="form.type" class="m-2" :placeholder="$t('其他')" style="width: 120px;height:32px"
        @change="handleSelectChange">
        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
    </div>
    <div class="inner inner2">
      <span>{{ $t('内容') }}:</span>
      <el-input v-model="form.content" />
    </div>
    <div class="inner inner3">
      <span>{{ $t('开始日期') }}：</span>
      <div class="block">
        <el-date-picker v-model="form.starttime" type="date" value-format="YYYY-MM-DD" />
      </div>
    </div>
    <div class="inner inner4">
      <span>{{ $t('结束日期') }}：</span>
      <div class="block">
        <el-date-picker v-model="form.endtime" type="date" value-format="YYYY-MM-DD" />
      </div>
    </div>
    <div class="inner inner5">
      <div style="
          height: 33px;
          border-radius: 5px;
          background-color: #f6d39c;
          display: flex;
          justify-content: center;
          align-items: center;
          margin-right: 10px;
          border:none;
          display: inline-block;
           padding-left: 5px;
            padding-right: 5px;
            padding-top: 5px;
            box-sizing: border-box;
        " class="bt" @click="select">
        <el-icon style="font-size: 16px; margin-right: 5px">
          <Search />
        </el-icon>
        <span>{{ $t('查询') }}</span>
      </div>
    </div>
  </div>
  <div class="box3">
    <el-table :data="tableData" width="90%"
      style="font-size: 14px;margin-top: 20px;background-color: #282d37;overflow-x: auto;"
      :header-cell-style="{ background: '#282d37', height: '30px' }">
      <el-table-column prop="type" :label="$t('类型')" min-width="80" sortable />
      <el-table-column prop="id" label="ID" width="80" v-if="0 == 1" />
      <el-table-column prop="content" :label="$t('内容')"  min-width="200" sortable />
      <el-table-column prop="createtime" :label="$t('反馈时间')"  min-width="150" sortable />
      <el-table-column prop="is_reply" :label="$t('是否回复')"  min-width="100" sortable />
      <el-table-column prop="content_reply" :label="$t('回复内容')"  min-width="200" sortable />
      <el-table-column prop="updatetime" :label="$t('回复时间')"  min-width="100" sortable />
      <el-table-column :label="$t('操作栏')" min-width="100" fixed="right">
        <template #default="{ row }">
          <div style="
          width: 60px;
          height: 28px;
          border-radius: 5px;
          background-color: #f6d39c;
          display: flex;
          justify-content: center;
          align-items: center;
          margin-right: 10px;
          
        " @click="openDetail(row.id)" class="bt">
            <el-icon style="font-size: 14px; margin-right: 5px ;color:black">
              <View />
            </el-icon>
            <span style="font-size: 13px; color:black">{{ $t('查看') }} </span>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <div class="block" style="margin-top: 20px;">
      <el-pagination v-model:current-page="form.page"  background layout="prev, pager, next" :total="pageTotal"
        :default-page-size="15" @current-change="handlePageChange" />
    </div>
  </div>

  <!--查看 谈话框  -->
  <el-dialog v-model="dialog" title="Tips" width="800px" draggable style="background-color: #272b37;">
    <template #header="{ close, titleId, titleClass }">
      <div class="my-header">
        <p style="color:white;">{{ $t('反馈详情') }}</p>
      </div>
    </template>
    <div style="color: #fff;">
      <h2>{{ $t('反馈类型') }}：{{ detail.type }}</h2>
      <p>{{ $t('用户ID') }}: {{ detail.member_id }}</p>
      <p>{{ $t('反馈内容') }}: {{ detail.content }}</p>
      <p>{{ $t('反馈时间') }}: {{ detail.createtime }}</p>
      <p v-if="detail.is_reply === 1">
        {{ $t('回复内容') }}: <span v-html="detail.content_reply"></span>
         <p>{{ $t('回复时间') }}：{{ detail.updatetime }}</p>
      </p>
      <p v-else>{{ $t('尚未回复') }}</p>

      <!--  <p>管理员ID: {{ detail.admin_id }}</p>
      <p>管理员姓名: {{ detail.admin_name || '无' }}</p> -->
    </div>
  </el-dialog>
  <!-- 留言 谈话框 -->
  <el-dialog v-model="dialogLeave" title="Tips" width="800px" draggable style="background-color: #272b37;">
    <template #header="{ close, titleId, titleClass }">
      <div class="my-header">
        <p style="color:white;">{{ $t('留言') }} </p>
      </div>
    </template>
    <div style="margin: 15px 0;color: white;">
      {{ $t('反馈类型') }}:
      <el-select v-model="formTwo.type" class="m-2" :placeholder="$t('其他')" style="width: 120px;height:32px"
        @change="handleSelectChange">
        <el-option v-for="item in option" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
    </div>
    <div style="border: 1px solid #ccc;">
      <Editor style="height: 300px; overflow-y: hidden;" :defaultConfig="editorConfig" v-model="formTwo.content"
        @onCreated="onCreated" />
    </div>
    <div style="margin: 15px 0;width: 100%;">
      <div style="
          width: 80px;
          height: 35px;
          border-radius: 5px;
          background-color: #f6d39c;
          display: flex;
          cursor: pointer;
          justify-content: center;
          align-items: center;
          margin-right: 10px;
          margin: auto;
          color: black;
        " @click="submit">
        <el-icon style="font-size: 14px; margin-right: 5px">
          <Select />
        </el-icon>
        <span style="font-size: 13px">{{ $t('提交') }}</span>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import { ElNotification } from 'element-plus'
import {
  feedbackListApi,
  feedbackDetailApi,
  feedbackSubmitApi
} from '@/api/index'
import {
  HomeFilled,
  Promotion,
  Pointer,
  Edit,
  Search,
  Plus,
} from "@element-plus/icons-vue";
export default {
  components: { Editor, Toolbar },
  data() {
    return {
      pageTotal: '',
      editor: null,
      toolbarConfig: {},
      editorConfig: {
        placeholder: this.$t('请输入内容...'),
      },
      editorRef: null,
      dialogLeave: false,
      options: [
        {
          value: '',
          label: this.$t('全部'),
        },
        {
          value:this.$t('注册') ,
          label: this.$t('注册'),
        },
        {
          value: this.$t('登录'),
          label: this.$t('登录'),
        },
        {
          value:this.$t('出金') ,
          label:this.$t('出金') ,
        },
        {
          value:this.$t('入金') ,
          label: this.$t('入金'),
        },
        {
          value:this.$t('银行卡') ,
          label:this.$t('银行卡') ,
        },
        {
          value:this.$t('其他') ,
          label: this.$t('其他'),
        },
      ],
      option: [
        {
          value:this.$t('其他') ,
          label: this.$t('其他'),
        },
        {
          value:this.$t('注册') ,
          label: this.$t('注册'),
        },
        {
          value: this.$t('登录'),
          label: this.$t('登录'),
        },
        {
          value:this.$t('出金') ,
          label:this.$t('出金') ,
        },
        {
          value:this.$t('入金') ,
          label: this.$t('入金'),
        },
        {
          value:this.$t('银行卡') ,
          label:this.$t('银行卡') ,
        },

      ],
      dialog: false,
      detail: '',
      form: {
        page: '1',
        starttime: '',
        endtime: '',
        type: '',
        content: ''
      },
      formTwo: {
        type: this.$t('其他'),
        content: '',
      },
      dialogVisible: false,
      tableData: [
      ],
      keywords: '',
    };
  },
  methods: {
    onCreated(editor) {
      this.editor = Object.seal(editor) // 【注意】一定要用 Object.seal() 否则会报错
    },
    handleSelectChange() {
      console.log(this.form.page);
    },
    // 页码改变时
    handlePageChange() {
      this.getFeedbackList()
    },
    // 查询
    select() {
      this.getFeedbackList()
    },
    // 获取反馈列表
    getFeedbackList() {
      const token = localStorage.getItem('token');
      this.form.token = token
      feedbackListApi(this.form).then(res => {
        this.pageTotal = res.data.total
        this.tableData = res.data.data
      })
    },
    // 获取反馈详情
    openDetail(id) {
      const token = localStorage.getItem('token')
      feedbackDetailApi({ token, id }).then(res => {
        this.dialog = true
        console.log(res.data);
        this.detail = res.data
      })
    },
    // 提交反馈
    submit() {
      const token = localStorage.getItem('token')
      this.formTwo.token = token
      feedbackSubmitApi(this.formTwo).then(res => {
        ElNotification({
          message: res.msg,
          duration: 500,
          onClose: () => {
            this.dialogLeave = false
            // 刷新页面
            window.location.reload();
          }
        });
      })
    },
    open() {
      this.dialogLeave = true
    }
  },

  mounted() {
    this.getFeedbackList()
  },
  beforeDestroy() {
    const editor = this.editor
    if (editor == null) return
    editor.destroy() // 组件销毁时，及时销毁 editor ，重要！！！
  }
};
</script>
<style src="@wangeditor/editor/dist/css/style.css"></style>
<style lang="scss" scoped>
:deep(.el-progress-bar__outer) {
  background-color: rgba(255, 255, 255, 0.4);
  /* lightgray, but transparent */
}

/* 进度条颜色 我需要的是渐变色 */
:deep(.el-progress-bar__inner) {
  background-color: white;
  //background: linear-gradient(90deg, #FEC015 0%, #FE8B25 100%);
}

.box1:hover {
  cursor: pointer;
}

.bt:hover {
  cursor: pointer;
}

.custom-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  //gap: 10px;

  color: white;
}

.topbox {
  width: 100%;
  height: 21px;
  display: flex;
  font-size: 13px;

  // justify-content: space-around;
  .small {
    width: 152px;
    // background-color: pink;
  }

  .small2 {
    width: 152px;
    // background-color: pink;
  }
}

.chart-wrapper {
  width: 100%;
  /* 确保内部图表容器充满el-col */
}

.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  /*   .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  } */

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

.box2 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  color: white;

  :deep(.el-input__wrapper) {
    background-color: black;
    height: 32px;
    box-shadow: none;
    color: white;

  }

  .inner {
    margin-right: 10px;
    margin-bottom: 5px;
    display: flex;
    justify-content: center;
    align-items: center;

    span {
      margin-right: 10px;
    }
  }

  .inner1 {
    :deep(.el-input__wrapper) {
      box-shadow: none;
      color: white;
      background-color: black;
    }
  }

  .inner2 {
    .el-input {
      width: 220px;
    }
  }

  .inner3 {
    align-items: center;
    display: flex;
  }

  .inner4 {
    align-items: center;
    display: flex;


    .demo-date-picker {
      display: flex;
      width: 100%;
      padding: 0;
      flex-wrap: wrap;
    }

    .demo-date-picker .block {
      padding: 30px 0;
      text-align: center;
      border-right: solid 1px var(--el-border-color);
      flex: 1;
    }

    .demo-date-picker .block:last-child {
      border-right: none;
    }

    .demo-date-picker .demonstration {
      display: block;
      color: var(--el-text-color-secondary);
      font-size: 14px;
      margin-bottom: 20px;
    }
  }

  .inner5 {
    color: #303133;
  }
}

.box3 {
  color: white;

  :deep(.el-table thead) {
    background-color: #2d303d;
    color: white;
  }

  :deep(.el-table__body-wrapper tr td) {
    background-color: #2d303d;
    color: white;
  }

  :deep(.el-table td) {
    border-bottom: 3px solid black;
  }

  :deep(.el-pagination__total) {
    color: #fff !important;
  }

  :deep(.el-pagination__jump) {
    color: #fff !important;
  }

  :deep(.el-pager li) {
    color: #fff !important;
  }

  :deep(.el-input__inner) {
    color: #fff !important;
  }

}

:deep(.el-pagination button) {
  background-color: black;
  color: white;
}

:deep(.el-pager li) {
  background-color: black;
  // color:white;

}

:deep(.el-input__wrapper) {
  background-color: black;
  box-shadow: none;
}

:deep(.el-input__inner) {
  color: #fff;
}

.el-dialog {
  p {
    margin: 10px 0;
  }
}

:deep(.el-pagination) {
  .el-pager li {
    background-color: #000;
  }
}

:deep(.el-pagination.is-background .btn-next) {
  background-color: #000;
}

:deep(.el-pagination.is-background .btn-prev) {
  background-color: #000;
}

:deep(.el-pagination.is-background .el-pager li.is-active) {
  background-color: #999;
}</style>
